// pages/Projects/SearchShareBrokerage/SearchShareBrokerage.js
//获取应用实例
const app = getApp()
import { queryShareAwardRecord } from '../../../api/reward';

Page({

  /**
   * 页面的初始数据
   */
  data: {
    customerName: '',
    loading: true,
    noMore: false,
    loadingFailed: false,
    isReachBottom: false,
    page: 1,
    dataList: [],
    shareTitle: app.globalData.global.shareTitle,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      page: 1,
      startTime: '',
      endTime: '',
    })
    this.getData();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    let userId = wx.getStorageSync('userId')
    return {
      title: this.data.shareTitle,
      path: '/pages/Tabbar/Home/Home?scene='+userId,
    }
  },
  onChange(event) {
    // event.detail 为当前输入的值
    console.log(event.detail);
    this.setData({
      customerName: event.detail
    })
  },
  // 获取列表数据
  getData(){
    let _this = this;
    queryShareAwardRecord('','',_this.data.customerName,_this.data.page)
    .then( res => {
      if(res.success){
        var list = _this.data.dataList;
        if(_this.data.page == 1){
          list = res.data.records;
        }else{
          list.concat(res.data.records);
        }
        _this.setData({
          dataList: list,
          totalAmount: res.data.totalAwardAmount ?? 0.0,
          noReceiveAmount: res.data.waitSubmitAwardAmount ?? 0.0,
          receiveAmount: res.data.waitIssuedAwardAmount ?? 0.0,
          page: _this.data.page+1,
        })
        if(_this.data.page * 10 >= res.data.totalCount){
          _this.setData({
            isReachBottom: false,
            noMore: true,
            loading: false,
            loadingFailed: false,
          })
        }else{
          _this.setData({
            isReachBottom: true,
            noMore: false,
            loading: false,
            loadingFailed: false,
          })
        }
      }else{
        wx.showToast({
          title: res.errMessage,
          icon: 'none',
        })
      }
    })
  },
})